<template>
  <div>
    <!-- 搜索 -->
    <TopFilter :list="topFilterInit" :cols="3" :collapse="collapse" labelWidth="90" @filterChange="changeHandle"></TopFilter>
    <!-- table -->
    <FilterTable height="auto" selectionType="single" ref="table" :columns="columns" :params="fetchParams" :fetchapi="fetchapi" :dataSource="dataList" :datakey="'records'" :onColumnsChange="columns => (this.columns = columns)" :onRowSelectChange="selectChange"> </FilterTable>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <multiuse-button type="primary" :click="saveDialog.bind()">确 定</multiuse-button>
      <multiuse-button @click="closeDialog">关 闭</multiuse-button>
    </div>
    <BaseDialog :visible.sync="model" :title="'车型选择'" destroyOnClose width="850px" :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}">
      <vehicle @close="close" @save="save"></vehicle>
    </BaseDialog>
  </div>
</template>
<script>
  import {getListByPage} from '@/api/claim/factory/QualityInformationManagement_OEM/QualityInformationExamine';
  import vehicle from '../../BasicData/ClaimApplication/vehicle';
  import { getPartType } from '@/api/dictionary/index';

  export default {
    // mixins: [dictionary],
    components: {
      vehicle,

    },
    data() {
      return {
        dataList: [],
        visible: false,
        visibleDrawer: false,
        collapse: false,
        infoId: null,
        topFilterInit: this.topFilterInitFun(),
        flterValue: {}, //参数
        columns: this.creatHeader(),
        // fetchApi: getUser,
        fetchParams: {
          status:2
        }, //ipa 接口
        selectedRows: [], //选中经销商
        fetchapi :getListByPage,
        model:false,
      };
    },
    created() {
      this.chuqi();
      // // this.dataList = [...res.data.items];
      // console.log(this.dataList);
    },
    methods: {
      async chuqi() {
        const res1 = await getPartType({type: 5561});
        delete res1.data[0];
        delete res1.data[2];
        delete res1.data[3];
        delete res1.data[4];
        delete res1.data[6];
        delete res1.data[7];
        if (res1.resultCode == 200) {
          this.topFilterInit.find(x => x.fieldName == 'reportStatus').itemList = res1.data.map(y => ({
            text: y.codeCnDesc,
            value: y.codeId
          }));
        }
      },
      //搜索数据
      topFilterInitFun() {
        return [
          {
            type: 'INPUT',
            label: '质量报告单号',
            fieldName: 'reportNo',
            placeholder: '请输入',
            initialValue: ''
          }, {
            type: 'INPUT',
            label: '索赔单号',
            fieldName: 'cmsClaimNo',
            placeholder: '请输入',
            initialValue: ''
          },

          {
            type: 'INPUT',
            label: '维修工单号',
            fieldName: 'roNo',
            placeholder: '请输入',
            initialValue: ''
          },
          {
            type: 'INPUT',
            label: 'VIN',
            fieldName: 'vin',
            placeholder: '请输入',
            initialValue: ''
          },
          {
            type: 'INPUT',
            label: '主损件名称',
            fieldName: 'partName',
            placeholder: '请输入',
            initialValue: ''
          },
          {
            type: 'INPUT',
            label: '主损件代码',
            fieldName: 'partCode',
            placeholder: '请输入',
            initialValue: ''
          },
          {
            type: 'INPUT',
            label: '车型',
            fieldName: 'modelCode',
            readonly: true, // 只读
            unitRender: p => {
              return (
                <div>
                <multiuse-button icon="el-icon-search" onClick={() => this.modelTurnOn()}/>
              </div>
            );
            }
          },
          {
            type: 'RANGE_DATE',
            label: '申请日期',
            fieldName: 'startTime|endTime',
            placeholder: '请输入',
            initialValue: ''
          },
          {
            type: 'SELECT',
            label: '质量报告状态',
            fieldName: 'reportStatus',
            itemList: [],
            readonly: true // 只读
          },
        ];
      },
      //搜索获取数据
      changeHandle(val) {
        this.fetchParams=Object.assign({},val,{ status: 2});
        console.log(val);
      },
      //table表头和数据源
      creatHeader() {
        return [
          {
            title: '序号',
            dataIndex: 'index',
            width: 80,
            sorter: true,
            render: props => {
              return <span>{props.row.index + 1}</span>;
            }
          },
          // {
          //   title: '操作',
          //   dataIndex: 'column-action',
          //   width: 100,
          //   fixed: 'left',
          //   render: props => {
          //     return (
          //       <div style="text-align:center">
          //         <multiuse-button type="primary" icon="el-icon-edit" circle></multiuse-button>
          //         <multiuse-button type="primary" icon="el-icon-delete" circle></multiuse-button>
          //       </div>
          //     );
          //   }
          // },
          { title: '质量报告状态', dataIndex: 'statusStr', sorter: true },
          { title: '质量报告单号', dataIndex: 'reportNo', sorter: true },
          { title: '索赔单号', dataIndex: 'cmsClaimNo', sorter: true },
          { title: '维修工单号', dataIndex: 'roNo', sorter: true },
          { title: 'VIN', dataIndex: 'vin', sorter: true },
          { title: '生产日期', dataIndex: 'prodDate', sorter: true },
          { title: '销售日期', dataIndex: 'saleDate', sorter: true },
          { title: '车型名称', dataIndex: 'modelName', sorter: true },
          { title: '主损件代码', dataIndex: 'partCode', sorter: true },
          { title: '主损件名称', dataIndex: 'partName', sorter: true },
          { title: '行驶里程', dataIndex: 'driveMile', sorter: true },
          { title: '故障现象代码', dataIndex: 'faultCode', sorter: true },
          { title: '故障现象名称', dataIndex: 'faultName', sorter: true },
          { title: '故障原因代码', dataIndex: 'sysCode4', sorter: true },
          { title: '故障原因名称', dataIndex: 'sysName4', sorter: true },
          { title: '维修开始时间', dataIndex: 'serviceBeginDate', sorter: true },
          { title: '维修结束时间', dataIndex: 'serviceEndDate', sorter: true },
          { title: '案例主题', dataIndex: '', sorter: true },
          { title: '申请时间', dataIndex: 'applyAt', sorter: true },
          { title: '申请人', dataIndex: 'applyBy', sorter: true },
          { title: '审核时间', dataIndex: 'checkAt', sorter: true },
          { title: '审核人', dataIndex: 'checkBy', sorter: true }          // ,
          // { title: '员工代码', dataIndex: 'employeeNo', sorter: true },
          // { title: '员工姓名', dataIndex: 'employeeName', sorter: true },
          // {
          //   title: '性别',
          //   dataIndex: 'gender',
          //   sorter: true,
          //   render: props => {
          //     return <span>{this.createDictText(props.row.gender, '1056')}</span>;
          //   }
          // },
          // { title: '手机', dataIndex: 'phone', sorter: true },
          // { title: '身份证号码', dataIndex: 'certificateId', sorter: true }
        ];
      },
      //选中
      selectChange(rows) {
        this.selectedRows = rows;
        console.log(this.selectedRows);
      },
      //保存
      saveDialog() {
        this.$emit('save', this.selectedRows);
      },
      //取消操作
      closeDialog() {
        this.$emit('close', { visible: false, data: this.selectedRows, type: 'close' });
      },
      chooseOrderNo() {
        this.visible = true;
      },
      modelTurnOn() {
        this.model = true;
      },
      save(obj) {
        this.model = false;
        this.topFilterInit.find(x => x.fieldName == 'modelCode').initialValue = obj[0].modelCode;
      },
      close() {
        this.model = false;
        this.fetchParams = { ...this.fetchParams };
      },
    }
    // mounted() {
    //   this.BaseTable = this.$refs.listModal.$refs.pageTable;
    // }
  };
</script>

<style lang="less" scoped></style>
